package com.hongyue.dey02;

import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入起始字符");
        String scrStr = sc.nextLine();
//        String scrStr = "java woaijava,i like jajavava i enjoy java";
        System.out.println("请输入要删除的字符");
        String delStr = sc.nextLine();
//        String delStr = "java";
        int cs = jige(scrStr, delStr);
        for (int i = 0; i < 3; i++) {
            scrStr = scrStr.replace(delStr, "");
        }
        System.out.println("源字符串中总共包含:" + cs + "个" + delStr + "删除" + delStr + "后的字符串为:" + scrStr);
    }

    private static int jige(String scrStr, String delStr) {
        int a = 0;
        int rear = scrStr.lastIndexOf(delStr);
        for (int i = -1; i < rear; ) {
            i = scrStr.indexOf(delStr, i + 1);
            a++;
        }
        scrStr = scrStr.replace(delStr, "");
        if (scrStr.lastIndexOf(delStr) != -1) {
            int cs = jige(scrStr, delStr);
            a += cs;
        }
        return a;
    }
}
